package com.smart.five.ioc.factorybean;

import org.springframework.beans.factory.FactoryBean;

/**
 * 定制实例化car,用逗号分隔属性值
 *
 * @author junrui.wang
 * @create 2018/6/14
 */
public class CarFactoryBean implements FactoryBean<Car> {
    private String carInfo;

    public String getCarInfo() {
        return carInfo;
    }

    //接收逗号分隔的参数
    public void setCarInfo(String carInfo) {
        this.carInfo = carInfo;
    }

    public Car getObject() throws Exception {
        Car car = new Car();
        String[] info = carInfo.split(",");
        car.setBrand(info[0]);
        car.setColor(info[1]);
        car.setMaxSpeed(Integer.parseInt(info[2]));
        return car;
    }

    public Class<?> getObjectType() {
        return Car.class;
    }

    /**
     * true：singleton，单例会放spring缓存。false:prototype
     * @return
     */
    public boolean isSingleton() {
        return true;
    }
}
